﻿using System;
using System.Web.UI;
using mojoPortal.Web.RS.SBM.AppCode.Lib;

 
namespace mojoPortal.Web.RS.SBM
{
    public partial class RSWorkOrderDetail2 : RSBasePage
    {
        int _companyid = 0;
        int _workorderid = 0;
        int _locationid = 0;

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }

        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["workorderid"] != null)
                _workorderid = Convert.ToInt32(Request.QueryString["workorderid"].ToString());

            if (!Page.IsPostBack)
            {
                InitializeReadyServicePage();
                RSUserIdentity userIdentity = GetRSUserIdentity();
                _companyid = userIdentity.RSCompanyId;

                if (_companyid > 0)
                {
                    SetRSPageHeader("WorkOrder Detail");
                    
                    _locationid = RSSBMCommonFunctions.GetLocationIDByWorkOrderID(_companyid, _workorderid);
                    ucLocationHeaderControl.LoadLocationHeader(_companyid, _locationid);
                    bool hasData = ucWorkOrderControl.LoadWorkOrderDataByID(_companyid, _workorderid);
                    if (hasData)
                    {
                        ucWorkOrderTaskListControl.LoadWorkOrderTaskListByID(_companyid, _workorderid);
                        ucWorkOrderPartListControl.LoadWorkOrderPartListByID(_companyid, _workorderid);
                        ucWorkOrderEquipListControl.LoadWorkOrderEquipListByID(_companyid, _workorderid);
                        ucWorkOrderIssueListControl.LoadWorkOrderIssueListByID(_companyid, _workorderid);
                        ucWorkOrderInvoiceListControl.LoadInvoiceDataByWorkOrderID(_companyid, _workorderid);

                        lblWorkOrderInvoice.Text = "WorkOrder ID: " + _workorderid.ToString();
                        lblWorkOrderEquip.Text = "WorkOrder ID: " + _workorderid.ToString();
                        lblWorkOrderIssue.Text = "WorkOrder ID: " + _workorderid.ToString();
                        lblWorkOrderPart.Text = "WorkOrder ID: " + _workorderid.ToString();
                        lblWorkOrderTask.Text = "WorkOrder ID: " + _workorderid.ToString();
                    }
                }


                if (Request.QueryString["tabindex"] != null)
                    tcWorkOrderDetail.ActiveTabIndex = Convert.ToInt16(Request.QueryString["tabindex"].ToString());
                else
                    tcWorkOrderDetail.ActiveTabIndex = 0;
            }
        }

        protected void btnAddAdHocInvoice_Click(Object sender, EventArgs e)
        {

        }
        protected void btnAddIssues_Click(Object sender, EventArgs e)
        {
            RSUserIdentity userIdentity = GetRSUserIdentity();
            if (userIdentity.RSCanWrite)
            {
                Response.Redirect("~/RS/SBM/RSManageIssue.aspx?action=add&workorderid=" + _workorderid);
            }
            else
                ucModalActionMessageControl.ShowModal("You Do Not Have Permission To Perform This Action!", "", false);
            
        }

        //protected void btnAddTask_Click(Object sender, EventArgs e)
        //{
        //    RSUserIdentity userIdentity = GetRSUserIdentity();
        //    if (userIdentity.RSCanWrite)
        //    {
        //        Response.Redirect("~/RS/SBM/RSManageWorkOrderTask.aspx?action=add&workorderid=" + _workorderid + "&taskid=0");
        //    }
        //    else
        //        ucModalActionMessageControl.ShowModal("You Do Not Have Permission To Perform This Action!", "", false);
        //}

        protected void btnAddParts_Click(Object sender, EventArgs e)
        {
            RSUserIdentity userIdentity = GetRSUserIdentity();
            if (userIdentity.RSCanWrite)
            {
                Response.Redirect("~/RS/SBM/RSShoppingPart.aspx?action=add&workorderid=" + _workorderid);
            }
            else
                ucModalActionMessageControl.ShowModal("You Do Not Have Permission To Perform This Action!", "", false);
        }

        protected void btnCheckoutEquip_Click(Object sender, EventArgs e)
        {
            RSUserIdentity userIdentity = GetRSUserIdentity();
            if (userIdentity.RSCanWrite)
            {
                Response.Redirect("~/RS/SBM/RSCheckoutEquip.aspx?action=add&workorderid=" + _workorderid);
            }
            else
                ucModalActionMessageControl.ShowModal("You Do Not Have Permission To Perform This Action!", "", false);
            
        }
    }
}